#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdbool.h>

// 检查密码强度的函数
void checkPasswordStrength(const char *password) {
    bool hasUpper = false;
    bool hasLower = false;
    bool hasDigit = false;
    bool hasSpecial = false;
    int length = strlen(password);
    
    // 检查每个字符
    for (int i = 0; i < length; i++) {
        if (isupper(password[i])) {
            hasUpper = true;
        } else if (islower(password[i])) {
            hasLower = true;
        } else if (isdigit(password[i])) {
            hasDigit = true;
        } else {
            hasSpecial = true;
        }
    }
    
    // 打印检查结果
    printf("\n密码强度检查结果:\n");
    printf("--------------------------------\n");
    printf("长度: %d\n", length);
    printf("包含大写字母: %s\n", hasUpper ? "是" : "否");
    printf("包含小写字母: %s\n", hasLower ? "是" : "否");
    printf("包含数字: %s\n", hasDigit ? "是" : "否");
    printf("包含特殊字符: %s\n", hasSpecial ? "是" : "否");
    printf("--------------------------------\n");
    
    // 评估密码强度
    int requirementsMet = 0;
    if (hasUpper) requirementsMet++;
    if (hasLower) requirementsMet++;
    if (hasDigit) requirementsMet++;
    if (hasSpecial) requirementsMet++;
    
    printf("密码强度: ");
    if (length >= 12 && requirementsMet == 4) {
        printf("非常强\n");
    } else if (length >= 8 && requirementsMet >= 3) {
        printf("强\n");
    } else if (length >= 6 && requirementsMet >= 2) {
        printf("中等\n");
    } else {
        printf("弱\n");
    }
    printf("--------------------------------\n");
}

int main() {
    char password[100];
    
    printf("密码强度检查工具\n");
    printf("请输入要检查的密码: ");
    
    // 读取密码输入
    if (fgets(password, sizeof(password), stdin) == NULL) {
        printf("读取输入失败!\n");
        return 1;
    }
    
    // 去除换行符
    password[strcspn(password, "\n")] = '\0';
    
    // 检查密码强度
    checkPasswordStrength(password);
    
    return 0;
}
